/*
 * $$Id: ForumDAO.java,v 1.65 2004/06/18 10:56:40 bel70 Exp $$
 *
 * ***** BEGIN LICENSE BLOCK *****
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License
 * at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 * the License for the specific language governing rights and
 * limitations under the License.
 *
 * The Original Code is jforum forum code.
 *
 * The Initial Developer of the Original Code is the JResearch, Org.
 * Portions created by the Initial Developer are Copyright (C) 2004
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *              Dmitry Belov <bel@jresearch.org>
 *
 * ***** END LICENSE BLOCK ***** */
/*
 * Created on 08.05.2003
 *
 */
package com.jred.jforum.dao.sqlmap;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.apache.struts.util.MessageResources;

import com.jred.jforum.beans.forum.Forum;
import com.jred.jforum.beans.forum.Message;
import com.jred.jforum.beans.forum.Tag;
import com.jred.jforum.beans.forum.Topic;


/**
 * DOCUMENT ME!
 * 
 * @author Bel
 */
public class ForumDAOImpl extends BaseDAO implements ForumDAO {


    public List getGroups(int userStatus, MessageResources messages){
        return getGroups(userStatus, true);
    }

    public List getGroups(int userStatus, boolean filled) {
    	return getSqlMapClientTemplate().queryForList("GET_ALL_GROUPS", null);
    }

	public List getForums(int groupid, boolean filled) {
		// TODO Auto-generated method stub
		return getSqlMapClientTemplate().queryForList("GET_ALL_FORUMS", String.valueOf(groupid));
	}
	
	public Forum getForumById(int forumid, boolean filled) {
		// TODO Auto-generated method stub
		return (Forum)getSqlMapClientTemplate().queryForObject("GET_FORUMS_BY_FORUMID", String.valueOf(forumid));
	}
	
	public List getTopics(int forumid, boolean filled) {
		// TODO Auto-generated method stub
		return getSqlMapClientTemplate().queryForList("GET_ALL_TOPICS", String.valueOf(forumid));
	}
	
	public List getTopicsByTagid(Map map, boolean filled){
		return getSqlMapClientTemplate().queryForList("GET_TOPICS_TAGID", map);
	}

	public Integer countForumTopics(int forumid){
		return  (Integer)getSqlMapClientTemplate().queryForObject("COUNT_THREADS", String.valueOf(forumid));		
	}
	
	public Message getLastMessageByForumid(int forumid){
		return (Message)getSqlMapClientTemplate().queryForObject("GET_LAST_MESS_FORUMID", String.valueOf(forumid));
	}
	
	public Message getLastMessageByThreadid(int threadid){
		return (Message)getSqlMapClientTemplate().queryForObject("GET_LAST_MESS_THREADID", String.valueOf(threadid));
	}

	public Topic getThreadById(int threadid, boolean filled) {
		// TODO Auto-generated method stub
		return (Topic)getSqlMapClientTemplate().queryForObject("GET_THREAD_THREADID", String.valueOf(threadid));
	}
	
	public List getForumTags(int forumid, boolean filled) {
		// TODO Auto-generated method stub
		return getSqlMapClientTemplate().queryForList("GET_FORUM_TAGS", String.valueOf(forumid));
	}

	public void updateThreadVcount(int threadid) {
		// TODO Auto-generated method stub
		getSqlMapClientTemplate().update("UPDATE_THREAD_VCOUNT", String.valueOf(threadid));
	}

	public List getThreadMessages(int threadid) {
		return getSqlMapClientTemplate().queryForList("GET_THREAD_MESSAGES", String.valueOf(threadid));
	}
	
	public Integer getNumReplys(int threadid) {
		return (Integer)getSqlMapClientTemplate().queryForObject("GET_NUM_REPLYS", String.valueOf(threadid));
	}
	
	/***********************       System         ***********************/
	public Map getSystemConstants(){
		return getSqlMapClientTemplate().queryForMap("GET_SYSTEM_CONSTANTS", null,"c_name","c_value");
	}
	
	public int addMessage(Message msg){
		return (Integer)getSqlMapClientTemplate().insert("ADD_MESSAGE", msg);
	}

	public Message getMessageInfo(int messageid) {
		// TODO Auto-generated method stub
		return null;
	}
	
}